home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.2 KB | 81 lines | [TEXT/GEOL] |
- Item 3215647 19-Feb-91 13:04PST
-
- From: U0922 NYU Medical Ctr, Martin Nachbar,HEP
-
- To: CPLUS.DEV$ C++ Interest List--Developers
-
- Item forwarded by ALCABES to CPLUS.APPLE$
-
- ------------------------------------------------------------------------------
-
- Sub: Ellipses
-
- Attn: CPLUS DEV$
- SentBy: Adam Hunger
- Date 2/19/91
- Subject Ellipses
- From Adam Hunger
- To CPLUS DEV$
-
- Subject: Time:12:05 PM
- OFFICE MEMO Ellipses Date:2/19/91
- Ok, I admit it...
-
- I've been writing my own vector and matrix classes for c++ so that I can hone
- my c++ skills and do cross development between our SGI and Mac.
-
- I wanted to write a constructor for my vector class that could take a variable
- number of floats. After several abortive attemps at using a vector::vector
- constructor, I finally traced the problem down to what appears to be a stack
- handling error, compiler bug, or user stupidity.
-
- I looked for a source that might work (source code devoid of my human
- frailties). On page 123 of "The C++ Answer Book" by Tony L. Hansen I found an
- error routine (included in full for you compilation pleasure) which I modified
- (after testing) to include floats. The footnote on the bottom of the page
- says:
-
- "ANSI C has changed the rules slightly from those in effect when The C++
- Programming Language was written. Formerly, all variables of type char, short
- and float were automatically promoted to ints and doubles when passed to
- functions. C++ and C compilers are now required to do this only when a
- variabale argument list is being used or when, in the case of C, the older
- function declaration style is used. Otherwise, the compiler is free to pass a
- char on the stack as a char, and likewise a short and a float." Whew.
-
- The declaration:
- void error(const char *fmt ...)
- and the use of <stdarg.h> works splendidly for char and int data; however,
- pass a float, and you'll see all sorts of garbage (the SGI will crash). This
- made me wonder if my float was being promoted to a double. I wrote a little
- stack sniffer that used a char * pointer to walk byte by byte (forwards and
- backwards) through the stack and recaste the pointer to floats and doubles.
- I've tried compiliing with all floats as doubles to eliminate the possibility
- of float promotion to doubles; this also failed.
-
- The problem is that these stack errors only occur for undeclared arguments.
- For MPW C++ 3.1 if you have a function (not even a member function or a
- constructor) such as:
-
- int passit(int n, float f1 ...)
- where n is the number of floats being passed
- f1 is the first float
-
- Then you can create a pointer to f1, but all arguments after f1 are garbled.
- For:
-
- int passit(int n, float f1, float f2 ...)
-
- you can create a float * fptr to f1, and use it to walk to f2, but all
- arguments on the stack after f2 are then garbled (or nonexistant?...I doubt
- it).
-
- What is going on? Are bytes being reversed on the stack for doubles? What's
- happening with the stackframe? Why should something apparently so easy waste
- so much of my time?
-
- Many thanks for any input at all,
-
- Adam Hunger, 212-263-5744
-
-